#!/usr/bin/python

# ----------------- BEGIN LICENSE BLOCK ---------------------------------
#
# Copyright (c) 2019-2021 Intel Corporation
#
# SPDX-License-Identifier: LGPL-2.1-only
#
# ----------------- END LICENSE BLOCK -----------------------------------

"""
This module uses pygccxml and py++ to generate
Python interfaces for all classes and datatypes
of the ad_rss_map_integration library.

The resulting library is called libad_rss_map_integration_python
"""

from python_wrapper_helper import generate_python_wrapper, post_process_python_wrapper


def main():
    """
    Main function to generate Python-C++ binding code
    """
    include_dirs = {
        "@GENPY_INCLUDE_DIRS@",
        #"@CMAKE_CURRENT_LIST_DIR@/../generated/include/",
        "@CMAKE_CURRENT_LIST_DIR@/../include/"
    }

    declarations={"toString", "fromString", "std::to_string", "std::sqrt", "std::fabs", "std::numeric_limits"}

    main_namespace="ad::rss::map"

    declarations_component=declarations.copy()
    declarations_component.add(main_namespace)

    header_dirs = {
        "@CMAKE_CURRENT_LIST_DIR@/../include/ad/rss/map"
    }

    ignore_files = {
        # issue: std::shared_ptr usage, but these files are not explicity required within python for now
        "RssObjectConversion.hpp",
        "RssSceneCreator.hpp",
    }
    ignore_declarations={}
    additional_includes={}

    component = "map"
    generate_python_wrapper(library_name=component,
                            cpp_filename="AdRss-{}-PythonWrapper.cpp.in".format(component),
                            header_directories=header_dirs,
                            include_paths=include_dirs,
                            main_namespace=main_namespace,
                            declarations=declarations_component,
                            ignore_declarations=ignore_declarations,
                            ignore_files=ignore_files)

    additional_replacements = {
                ("BOOST_PYTHON_MODULE({}){{".format(component),
                 "void export_ad_rss_{}(){{\n\n".format(component) +
                 "  bp::object ad_rss_{}_module(bp::handle<>(bp::borrowed(PyImport_AddModule(\"{}\"))));\n".format(component, component) +
                 "  bp::scope().attr(\"{}\") = ad_rss_{}_module;\n".format(component, component) +
                 "  bp::scope submodule_scope = ad_rss_{}_module;\n\n".format(component) +
                 "  bp::scope().attr(\"__doc__\") = \"Python binding of ad_rss_map_integration ad::rss::{} C++ code for @PYTHON_BINDING_NAME@\";".format(component) +
                 "  bp::scope().attr(\"__copyright__\") = \"Copyright (C) 2019-2021 Intel Corporation\";" +
                 "  bp::scope().attr(\"__license__\") = \"LGPL-2.1-only\";"
                )}
    post_process_python_wrapper(header_directories=header_dirs,
                                cpp_filename_in="AdRss-map-PythonWrapper.cpp.in",
                                cpp_filename_out="AdRss-map-PythonWrapper.cpp",
                                additional_replacements=additional_replacements,
                                spdx_license="LGPL-2.1-only")

if __name__ == '__main__':
    main()
